﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Connectors;
using PServiceBus.Services.Gateway.Runtime;

namespace ChatServer {
    public class ChatRequest : ESBMessageRequest<ChatRequest, ChatResponse> {
        public string UserName { get; set; }
        public string Message { get; set; }
    }
    public class ChatResponse : ESBMessageResponse {
        public string UserName { get; set; }
        public string Message { get; set; }
    }
    class Program {
        static void Main(string[] args) {
            ESB.Authenticate("rpgmaker", "password1");
            ESB.ConfigWithWCFAddress("net.tcp://localhost:8000/ESBGateway");

            var server = new ChatResponse();
            server.Handle<ChatRequest, ChatResponse>((request, response) => {
                Console.WriteLine("Received Chat Request");
                response.UserName = String.Format("{0}Server", request.UserName);
                response.Message = "Server: Hello Client";
            });
            Console.WriteLine("Waiting for request.....");
            Console.ReadLine();
            server.Shutdown();
        }
    }
}
